package com.gxa.common.base;


import com.gxa.common.constant.Constants;

/**
 * 返回数据公共对象
 */
public class Result<T> {
    private Integer code; // 状态码
    private String message; // 提示信息
    private T data; // 返回数据

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Result() {

    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Result success(){
        return new Result(Constants.OK,Constants.MESSAGE_OK);
    }

    public static Result success(String message){
        return new Result(Constants.OK,message);
    }

    public static Result success(Integer code,String message){
        return new Result(code,message);
    }

    public static <T> Result<T> success(T data){
        return new Result(Constants.OK,Constants.MESSAGE_OK,data);
    }

    public static <T> Result<T> success(String message,T data){
        return new Result(Constants.OK,message,data);
    }

    public static Result error(){
        return new Result(Constants.ERROR,Constants.MESSAGE_ERROR);
    }

    public static Result error(String message){
        return new Result(Constants.ERROR,message);
    }

    public static Result error(Integer code,String message){
        return new Result(code,message);
    }
}
